#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#include <SPI.h>

#include <TensorFlowLite.h>
#include <tensorflow/lite/micro/all_ops_resolver.h>
#include <tensorflow/lite/micro/micro_error_reporter.h>
#include <tensorflow/lite/micro/micro_interpreter.h>
#include <tensorflow/lite/schema/schema_generated.h>
#include <tensorflow/lite/version.h>

#include "Arduino_BMI270_BMM150.h"
#include "model.h"

#include "echoNet.h"

EchoNet echo;
Matrix<float> testUpDim(T, N_INTERNAL_UNITS);
Matrix<float> test(T, V);

float p = 3.1415926;
tflite::MicroErrorReporter tflErrorReporter;
tflite::AllOpsResolver tflOpsResolver;
TfLiteTensor* tflInputTensor = nullptr;
TfLiteTensor* tflOutputTensor = nullptr;
const tflite::Model* tflModel = nullptr;
tflite::MicroInterpreter* tflInterpreter = nullptr;
constexpr int tensorArenaSize = 8 * 1024;
byte tensorArena[tensorArenaSize] __attribute__((aligned(16)));


void setup()
{
	Serial.begin(9600);
	while (!Serial);
	randomSeed(analogRead(A0));
	Serial.println("init ok !!!!!!!");

  EchoNet echo;

  tflModel = tflite::GetModel(model);
	if (tflModel->version() != TFLITE_SCHEMA_VERSION) {
		Serial.println("Model schema mismatch!");
		while (1);
	}

	tflInterpreter = new tflite::MicroInterpreter(tflModel, tflOpsResolver, tensorArena, tensorArenaSize, &tflErrorReporter);
	tflInterpreter->AllocateTensors();

	tflInputTensor = tflInterpreter->input(0);
	tflOutputTensor = tflInterpreter->output(0);

	Serial.println("ML done");
}

void loop()
{

}

void printMatrixToSerial(Matrix<float>& t) {
	Serial.print("[");
	for (int i = 0; i < t.rows(); i++) {
		Serial.print("[");
		for (int j = 0; j < t.cols(); j++) {
			Serial.print(t(i, j));
			Serial.print(",");
		}
		Serial.print("]");
		Serial.println();
	}
	Serial.print("]");
}